<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
		<div id="mainownservice">
			<h3><?php echo JText::_('OWNSERVICE_FAILED_TRANSACTIONS'); ?></h3>
			<hr />
			<script language="javascript" type="text/javascript">
				<!--
					function submitbutton(pressbutton)
					{
						var form = document.adminForm;

						if (form.boxchecked.value == 0){
							alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_FAILED_TRANSACTIONS', true ); ?>" );
						} else {
							submitform( pressbutton );
						}

					}
				//-->
			</script>
			<div id="toolbar">
				<a class="toolbar" onclick="submitbutton('resubmit');" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_RESUBMIT'); ?>" class="icon-32-forward"></span>
					<?php echo JText::_('OWNSERVICE_RESUBMIT'); ?>
				</a>
			</div>
			<div class="clear"> </div>
			<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm" autocomplete="off">
				<table>
					<tr>
						<td width="100%">
							<?php echo JText::_( 'OWNSERVICE_FILTER' ); ?>:<input type="text" name="search" value="<?php echo htmlspecialchars($this->lists['search']);?>"  onchange="document.adminForm.submit();" />
							<button onclick="this.form.submit();" class="button">
								<?php echo JText::_( 'Go' ); ?>
							</button>
							<button onclick="document.adminForm.search.value='';this.form.submit();" class="button">
								<?php echo JText::_( 'Reset' ); ?>
							</button>
						</td>
						<td nowrap="nowrap">
							<?php if( isset($this->lists['branch']) ) :?>
									<?php echo $this->lists['branch']; ?>
							<?php endif; ?>
						</td>
					</tr>
				</table>

				<table class="adminlist" cellspacing="1">
					<tr>
						<td align="center" class="tablelist">
							<?php echo JText::_('NUM'); ?>
						</td>
						<td align="center" class="tablelist">
							<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->rows); ?>);" />
						</td>
						<td align="center" class="tablelist">
							<?php echo JText::_('OWNSERVICE_RECEIVER_NO'); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_USER', 'u.name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort', 'OWNSERVICE_BANK_NAME', 'a.bank_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort', 'OWNSERVICE_BRANCH_CITY', 'a.branch_city', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_CREATE_DATE', 't.created', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_TRANSFER_ON', 't.requested_date', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_AMOUNT_TRANSFER', 't.amount', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_RATE', 't.rate', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_TOTAL_EXCHANGE', 't.total', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
					</tr>
				<tfoot>
					<tr>
						<td colspan="12"><?php echo $this->pageNav->getListFooter(true); ?></td>
					</tr>
				</tfoot>
				<tbody>
				<?php
					$k 			 	= 0;
					$priceformat 	= OwnserviceHelper::getParams('price_format', '#,###.##');
					$dateformat  	= OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 
					for($i=0,$n=count($this->rows);$i<$n;$i++):
					
						$row			= $this->rows[$i];
						$checked		= JHTML::_('grid.checkedout', $row, $i );
						$link			= JRoute::_('index.php?option=com_ownservice&controller=transaction&task=detail&id='.$row->id);
						$link_member	= JRoute::_('index.php?option=com_ownservice&controller=member&task=detail&id='.$row->memberid);
				?>
					<tr class="<?php echo "row$k"; ?>">
					<td align="center" class="inner_tablelist">
						<?php echo $this->pageNav->getRowOffset( $i ); ?>
					</td>
					<td align="center" class="inner_tablelist">
						<?php echo $checked; ?>
					</td>
					<td align="center" class="inner_tablelist">
						<a href="<?php echo $link; ?>">
							<?php echo $row->invoice; ?>
						</a>
					</td>
					<td align="center" class="inner_tablelist">
						<?php echo OwnserviceHelper::accountFormat($row->account); ?>
					</td>
					<td class="inner_tablelist">
						<a href="<?php echo $link_member; ?>">
							<?php echo $row->username; ?>
						</a>
					</td>
					<td class="inner_tablelist">
						<?php if($row->bank_name=='other'): ?>
							<?php echo $row->bank_other; ?>
						<?php else: ?>
							<?php echo $row->bank_name; ?>
						<?php endif; ?>
					</td>
					<td class="inner_tablelist"> 
						<?php echo $row->branch_city; ?>	
					</td>
					<td class="inner_tablelist" align="center">
						<?php echo JHTML::_('date', $row->created, $dateformat); ?>
					</td>
					<td class="inner_tablelist" align="center"> 
						<?php 
							if($row->requested_date != $this->db->getNullDate()) {
								echo JHTML::_('date', $row->requested_date, $dateformat);
							}
						?>
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php 
							echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); 
							$sum_amount = $sum_amount + $row->amount;
						?> AUD
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php
							$color = '';
							if($row->extrarate > 0.00 ) {
								$color = 'red';
							} else if($row->extrarate < 0.00) {
								$color = 'green';
							}
						?>
						<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px dotted #ccc;">
								<?php 
									echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th);
									$sum_rate = $sum_rate + $row->rate_th; 
								?> THB
							</div>
						<?php
							else:
								$sum_rate = $sum_rate + ($row->rate+$row->extrarate);  
							endif; 
						?>
						<div class ="<?php echo $color; ?>">
							<?php 
								echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate).' '.$row->rate_code; 
							?> 
						</div>
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php 
							/* total transfer */
							/*$color = '';
							if($row->extratotal > 0.00 ){
								$color = 'red';
								$total = $row->extratotal;	
							} else {
								$total = $row->amount * ($row->rate+$row->extrarate);
							}*/
						?>
						<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px dotted #ccc;">
								<?php 
									echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th);
									$sum_total = $sum_total + $row->total_th;
								?> THB
							</div>
						<?php
							else:
								if($row->extratotal > 0.00 ){
									$sum_total = $sum_total + $row->extratotal;  
								} else {
									$sum_total = $sum_total + ( ($row->amount * ($row->rate+$row->extrarate))- ($row->bankfee+$row->extrabfee));
								}
							endif; 
						?>
						<div class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
							<?php 
								if($row->extratotal > 0.00) {
									echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal).' '.$row->rate_code;
								} else {
									echo OwnserviceHelper::moneyFormat($priceformat,( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))).' '.$row->rate_code; 
								}
								?>
						</div> 
					</td>
				</tr>
				<?php $k = 1 - $k; endfor; ?>
				</tbody>
			</table>
			<input type="hidden" name="boxchecked" value="0" />
			<input type="hidden" name="id" value="" />
			<input type="hidden" name="status" value="" />
			<input type="hidden" name="option" value="com_ownservice" />
			<input type="hidden" name="task" value="failedtransactions" />
			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
			<input type="hidden" name="controller" value="transaction" />
			<input type="hidden" name="view" value="transactions" />
			<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
			<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
			<?php echo JHTML::_( 'form.token' ); ?>
		</form>
	</div>
</div>